﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;

namespace BUS
{
    public class HD_ChiTietBUS
    {
        public static bool LapCTHD(long mHD, long mPT, long sN)
        {
            return HD_ChiTietDAO.LapCTHD(mHD, mPT, sN);
        }

        public static double TinhTien(PhieuThueDTO PT)
        {
            int chk = 0;
            PhongDTO P = PhongBUS.LayTTPTheoMP(PT.MaPhong.MaPhong);
            List<KhachHangDTO> LKH = KhachHangBUS.LayDSKHTheoMPT(PT.MaPhieuThue);
            HD_ChiTietDTO CTHD = HD_ChiTietDAO.LayTTTheoMPT(PT.MaPhieuThue);

            double tT = 0;

            tT = CTHD.SoNgayThue * P.MaLoaiPhong.MaDonGia.DonGia;

            for (int i = 0; i < LKH.Count; i++)
            {
                if (LKH[i].MaLoaiKH.MaLoaiKH == 2)
                {
                    chk = 1;
                    break;
                }
            }

            if (LKH.Count == 3 && chk == 1)
            {
                tT = tT * 1.25 * 1.5;
            }

            if (LKH.Count == 3 && chk == 0)
            {
                tT = tT * 1.25;
            }

            if (LKH.Count < 3 && chk == 1)
            {
                tT = tT * 1.5;
            }

            HD_ChiTietDAO.UpdateTien(PT.MaPhieuThue, tT);

            return tT;

        }

        public static List<HD_ChiTietDTO> LayDSHDCTTheoMHD(long mHD)
        {
            return HD_ChiTietDAO.LayDSHDCTTheoMHD(mHD);
        }

        public static List<HD_ChiTietDTO> LayDSTheoMLP(long mLP)
        {
            return HD_ChiTietDAO.LayDSTheoMLP(mLP);
        }

        public static List<HD_ChiTietDTO> LayDSTheoMP(long mP)
        {
            return HD_ChiTietDAO.LayDSTheoMP(mP);
        }
    }
}
